import java.util.*;
import java.io.*;
public class test {
    // 牛客 mari和shiny
    public static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        String S = in.next();
        long h = 0;
        long y = 0;
        long s = 0;
        char[] arr = (" " + S).toCharArray();
        for(int i = 1;i <= n;i++){
            char c = arr[i];
            if(c == 'h'){
                h++;
            }else if(c == 'y'){
                y++;
            }
        }
        long sum = 0;
        for(int i = 1;i <= n;i++){
            char c = arr[i];
//当前位置之后的y数量-1
            if(c == 'y'){
                y--;
            }else if(c == 's'){
                s++;
            }else if(c == 'h'){
//h之前有多少s,就对sum加多少
                sum += 1l * s * y;
            }
        }
        System.out.println(sum);
    }
    // 牛客 水果大礼包
    public static void main1(String[] args) throws IOException {
        int n = in.nextInt();//苹果
        int m = in.nextInt();//桃子
        int a = in.nextInt();
        int b = in.nextInt();
        long max = 0;
// 先组成最多个数的"最贵礼包"
// 2苹1桃 -> a
// 1苹2桃 -> b
        int big = Math.max(a,b);
        boolean flg = big == a ? true : false;
//最贵礼包的数量
        long numbig = 0;
        long nummin = 0;
//a为最贵礼包
        if(!flg) {
            int tmp1 = n;
            int tmp2 = m / 2;
            numbig = Math.min(tmp1, tmp2);
            n -= numbig;
            m -= (numbig * 2);
            max = 1l * numbig * b;
            while (numbig > 0) {
                numbig--;
                n += 1;
                m += 2;
                while (n >= 2 && m >= 1) {
                    n -= 2;
                    m -= 1;
                    nummin++;
                }
                max = Math.max(max, (1l * numbig * b + 1l * nummin * a));
            }
            System.out.println(max);
        }
//b为最贵礼包
        else {
            int tmp1 = n / 2;
            int tmp2 = m;
            numbig = Math.min(tmp1, tmp2);
            n -= (numbig * 2);
            m -= numbig;
            max = 1l * numbig * a;
            while (numbig > 0) {
//还能组成b礼包
                numbig--;
                n += 2;
                m += 1;
                while (n >= 1 && m >= 2) {
                    n -= 1;
                    m -= 2;
                    nummin++;
                }
                max = Math.max(max, (1l * numbig * a + 1l * nummin * b));
            }
            System.out.println(max);
        }
// n : 7 m : 6
// a : 10 b : 8
    }
    // 洛谷 过河卒
    public static int[] dx = {0,1};
    public static int[] dy = {1,0};
    public static void main2(String[] args) throws IOException {
        int n = in.nextInt() + 1;
        int m = in.nextInt() + 1;
        int x = in.nextInt() + 1;
        int y = in.nextInt() + 1;
        List<Integer>[] set = new List[25];
        for(int i = 0;i < 25;i++){
            set[i] = new ArrayList<>();
        }
        set[x].add(y);
        set[x-2].add(y-1);
        set[x+2].add(y-1);
        set[x-2].add(y+1);
        set[x+2].add(y+1);
        set[x-1].add(y-2);
        set[x+1].add(y-2);
        set[x-1].add(y+2);
        set[x+1].add(y+2);
        long[][] dp = new long[n + 1][m + 1];
        dp[1][1] = 1;
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= m;j++){
                if(set[i].contains(j) || (i == 1 && j == 1)){
                    continue;
                }
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }
        System.out.println(dp[n][m]);
    }
}
class Read{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    int nextInt() throws IOException{
        return Integer.parseInt(next());
    }
    long nextLong() throws IOException{
        return Long.parseLong(next());
    }
    double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }
}
